package com.jerry.mingxing.ui.categroy;

import android.app.Activity;
import android.content.Context;
import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.jerry.mingxing.R;
import com.jerry.mingxing.ui.categroycategroy.CategroyCategroyFragment;
import com.jerry.mingxing.ui.categroybrand.CategroyBrandFragment;


import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2016/8/29.
 */
public class CategroyFragment extends Fragment {

    @Bind(R.id.categroyfragment_tablayout)
    TabLayout categroyfragmentTablayout;
    @Bind(R.id.categroyfragment_viewpager)
    ViewPager categroyfragmentViewpager;
    private View view;
    private Context context;
    private Activity activity;
    private String[] categroy_titile;
    private List<Fragment> totallist = new ArrayList<>();
    private CategroyCategroyFragment categroyFragment_left;
    private CategroyBrandFragment categroyFragment_right;
    private CategroyAdapter categroyAdapter;

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        activity = getActivity();
        context = getContext();
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.categroyfragment, container, false);
        ButterKnife.bind(this, view);
        initData();
        setAdapter();
        return view;
    }


    private void initData() {
        categroyFragment_left = new CategroyCategroyFragment();
        categroyFragment_right = new CategroyBrandFragment();
        categroy_titile = getResources().getStringArray(R.array.categroy_titile);
        totallist.add(categroyFragment_left);
        totallist.add(categroyFragment_right);
    }

    private void setAdapter() {
        categroyAdapter = new CategroyAdapter(getActivity().getSupportFragmentManager(), totallist, categroy_titile);
        categroyfragmentViewpager.setAdapter(categroyAdapter);
        categroyfragmentTablayout.setupWithViewPager(categroyfragmentViewpager);
        categroyfragmentTablayout.setTabTextColors(Color.BLACK,Color.RED);
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);

    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.unbind(this);
    }


}
